package com.wrb.entity;


import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @author haixingchen
 */
@Data
public class Response<T>  {

    private String code;

    private T result;

    private String msg;



    public static <T> Response<T>  success(T result){
        return success(result,null);
    }
    public static <T> Response<T>  success(){
        return success(null);
    }

    public static <T> Response<T>  success(T result,String msg){
        Response response = new Response();
        response.setCode(ResponseStatus.SUCCESS.getCode());
        response.setResult(result);
        response.setMsg(StringUtils.isEmpty(msg) ? ResponseStatus.SUCCESS.getMsg() : msg);
        return response;
    }

    public static <T> Response<T>  fail(ResponseStatus status){
        return fail(null,status);
    }

    public static <T> Response<T>  fail(T result,ResponseStatus status){
        Response response = new Response();
        response.setCode(status.getCode());
        response.setResult(result);
        response.setMsg(status.getMsg());
        return response;
    }
    public static <T> Response<T>  fail(T result,String msg){
        Response response = new Response();
        response.setCode(ResponseStatus.OTHERS_ERROR.getCode());
        response.setResult(result);
        response.setMsg(msg);
        return response;
    }
}
